package com.rocketmq.temp3.common.constant;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;

/**
 * 应用系统常量
 */
public interface AppConstant {
    /**
     * Redis三种使用模式
     */
    enum RedisModel {
        /**
         * 单节点模式
         */
        standalone,
        /**
         * 哨兵模式 + 主从复制 集群
         */
        sentinel,
        /**
         * 分片式集群
         */
        cluster;

        RedisModel() {
        }
    }

    /**
     * 定义系统中使用到的默认值
     */
    enum DefaultValue {
        NULL(null),
        NULL_PLACE_HOLDER("#{java.lang.String:null}");

        private Object defaultValue;

        DefaultValue(Object defaultValue) {
            this.defaultValue = defaultValue;
        }

        public Object getDefaultValue() {
            return defaultValue;
        }

        public String getAndCastString() {
            return String.valueOf(defaultValue);
        }
    }

    /**
     * 定义系统中使用到的日期格式
     */
    enum DatePattern {
        ;

        DatePattern() {
        }

        public static final String DATETIME_FORMATTER_VALUE = "yyyy-MM-dd HH:mm:ss";
        public static final DateTimeFormatter DATETIME_FORMATTER = parseOf("yyyy-MM-dd HH:mm:ss");
        public static final SimpleDateFormat DATETIME_FORMATTER_OLD = convertOf("yyyy-MM-dd HH:mm:ss");

        public static final String DATE_FORMATTER_VALUE = "yyyy-MM-dd";
        public static final DateTimeFormatter DATE_FORMATTER = parseOf("yyyy-MM-dd");
        public static final SimpleDateFormat DATE_FORMATTER_OLD = convertOf("yyyy-MM-dd");

        public static final String DATE_FORMATTER_EXTRA_VALUE = "yyyyMMdd";
        public static final DateTimeFormatter DATE_FORMATTER_EXTRA = parseOf("yyyyMMdd");
        public static final SimpleDateFormat DATE_FORMATTER_OLD_EXTRA = convertOf("yyyyMMdd");

        public static final String TIME_FORMATTER_VALUE = "HH:mm:ss";
        public static final DateTimeFormatter TIME_FORMATTER = parseOf("HH:mm:ss");
        public static final SimpleDateFormat TIME_FORMATTER_OLD = convertOf("HH:mm:ss");

        public static final String TIME_FORMATTER_EXTRA_VALUE = "HHmmss";
        public static final DateTimeFormatter TIME_FORMATTER_EXTRA = parseOf("HHmmss");
        public static final SimpleDateFormat TIME_FORMATTER_OLD_EXTRA = convertOf("HHmmss");

        private static DateTimeFormatter parseOf(String value) {
            return DateTimeFormatter.ofPattern(value);
        }

        private static SimpleDateFormat convertOf(String value) {
            return new SimpleDateFormat(value);
        }
    }

    /**
     * 定义创建Workbook的类型
     */
    enum WorkbookTypeEnum {
        /**
         * 定义枚举和枚举值
         */
        EXCEL_XLS("XLS"), EXCEL_XLSX("XLSX");

        WorkbookTypeEnum(String value) {
            this.value = value;
        }

        /**
         * 枚举值
         */
        private String value;

        /**
         * 获取枚举值
         *
         * @return 返回枚举值
         */
        public String getValue() {
            return this.value;
        }
    }
}
